package com.mixsmart.mobile.controller;

import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mixsmart.commonweb.helper.HttpRequestHelper;
import com.mixsmart.utils.Captcha;

/**
 * 验证码--控制器类
 * @author lmq
 * @version 1.0
 * @since JDK版本大于等于1.6
 * 2016年1月25日
 */
@Controller
public class CaptchaController extends BaseMobileController {

	/**
	 * 获取验证码
	 * @param request HTTP请求对象
	 * @param response HTTP回应对象
	 */
	@RequestMapping("/captcha.do")
	public void index(HttpServletRequest request, HttpServletResponse response) {
		logger.info("正在生成验证码-----");
		Captcha cap = new Captcha(120,32,20);
		String code = cap.getString();
		logger.info("正在生成验证码--[完成]--["+code+"]-");
		HttpRequestHelper.setSession(request, SESSION_CAPTCHA_LOGIN, code);
		try {
			ImageIO.write(cap.getBuffImage(), "JPEG", response.getOutputStream());
		} catch (IOException e) {
			e.printStackTrace();
		}
		cap = null;
	}
	
}
